package fr.afcepf.ai85.gepeto.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;


import fr.afcepf.ai85.ent.Ecole;
import fr.afcepf.ai85.ent.InscriptionEcole;
import fr.afcepf.ai85.ent.Niveauscolaire;
import fr.afcepf.ai85.hibernate.util.HibernateUtil;

public class ServiceInscriptionEcole {

	public Ecole rechercherEcoleByIdEleve(Integer idEleve) {
		Ecole ec=null;

		try
		{
			Session session = HibernateUtil.currentSession();
			Transaction tx = session.beginTransaction();
			Query hql = session.createQuery(
					"select insc.ecole FROM InscriptionEcole as insc inner join insc.ecole WHERE insc.eleve.idEleve like :nId" );
			hql.setInteger("nId", idEleve);
			
			List<Ecole> liste = hql.list();
	
			ec = liste.get(0);		
			//inscription.getEcole();
			tx.rollback();
			HibernateUtil.closeSession();
		}
		catch (Exception e) {
			// TODO: handle exception
			HibernateUtil.closeSession();
			e.printStackTrace();
		}


		return ec;
	}
	
	public Niveauscolaire rechercherInscriptionEcoleByIdEleve(Integer idEleve) {
		Niveauscolaire niv=null;

		try
		{
			Session session = HibernateUtil.currentSession();
			Transaction tx = session.beginTransaction();
			Query hql = session.createQuery(
					"select insc.niveauscolaire  FROM InscriptionEcole as insc inner join insc.ecole WHERE insc.eleve.idEleve like :nId" );
			hql.setInteger("nId", idEleve);
			
			List<Niveauscolaire> liste = hql.list();
	
			niv = liste.get(0);		
			//inscription.getEcole();
			tx.rollback();
			HibernateUtil.closeSession();
		}
		catch (Exception e) {
			// TODO: handle exception
			HibernateUtil.closeSession();
			e.printStackTrace();
		}


		return niv;
	}
	
//	public static void main(String[] args) {
//		System.out.println(rechercherInscriptionEcoleByIdEleve(12).getNomNiveau());
//	}
}
